<?php

import('pages.manager.ManagerHandler');
class CTKTTHHandler extends ManagerHandler {
	function CTKTTHHandler()
	{
		parent::ManagerHandler();
	}

	function CN_CTKT($args, &$request) {
		$xMode  = Request::getUserVar("Mode");
		if ($xMode !==null)
			$this->edit_createCTKTTH($request->getBaseUrl(), $args);
		else
			$this->listCTKTTH($request->getBaseUrl());

	}

	function CTKTTH_Del() {
	
		$journalid = Request::getUserVar('journalid') ;
		$Year = Request::getUserVar('year') ;
		$idphieu = Request::getUserVar('idphieu') ;

		$ctkthtDao =& DAORegistry::getDAO('CTKTTHDAO');
		$mysqlQ = "DELETE FROM CTKTTHDT".$journalid. $Year. "  WHERE idPhieu='". $idphieu. "'";
		$result =& $ctkthtDao->retrieve($mysqlQ);
		if (gettype($result) == 'object')
		{
		}
		else
		{
			echo 2;
			return;
		}

		$mysqlQ = "DELETE FROM CTKTTH".$journalid. $Year. "  WHERE idPhieu='". $idphieu. "'";
		$result =& $ctkthtDao->retrieve($mysqlQ);
		if (gettype($result) == 'object')
		{
			echo 1;
		}
		else
		{
			echo 2;
		}


	}


	function Ins_CTKT($args, &$request) {
		$xMode  = Request::getUserVar("Mode");
		$journalid = Request::getUserVar('journalid') ;
		$Year = Request::getUserVar('year') ;
		$soct = Request::getUserVar("soct");
		$ngct = Request::getUserVar("ngct");
		$lydo = Request::getUserVar("lydo");
		$tableArr = Request::getUserVar("tableArr");
		$cautruc = Request::getUserVar("cautruc");

		$codulieu = 0;
		$succ = 1;
		$mysql = array();
		$i = 0;

		foreach ($tableArr as $v) {
			$dulieu = ""; 
			$mysql[$i] = "" ;

			foreach ($v as $key=>$value) 
			{
				$dulieu .= "$value";
				$fdulieu = "$value";
				if ($fdulieu !== "")
				{		$mysql[$i] .= ", ". $cautruc[$key]."  = '".$value."'";
				}
			}
			if ($dulieu !== "")
			{
				$i++;
			}

		}

		if ($i==0)
		{
			echo "2";
			return ;
		}

		$mysql_pa = "INSERT INTO CTKTTH".$journalid. $Year. "  SET ";
		$mysql_pa .= "  soct='". $soct. "', ";
		$mysql_pa .= "  ngct='". $ngct. "', ";
		$mysql_pa .= "  lydo='". $lydo. "' ";

		//echo $mysql_pa;
		$ctkthtDao =& DAORegistry::getDAO('CTKTTHDAO');
		$result =& $ctkthtDao->retrieve($mysql_pa);
		$result =& $ctkthtDao->retrieve("SELECT MAX(idPhieu) as idPhieu FROM CTKTTH".$journalid. $Year);
		
		$newidPhieus =$result->GetRowAssoc(false);

		$newidPhieu = $newidPhieus["idphieu"];
		$mysql_pre = "INSERT INTO CTKTTHDT".$journalid. $Year. "  SET idPhieu='". $newidPhieu . "'";
		for ($dong = 0; $dong < $i ; $dong++) {
			$mysqlQ = $mysql_pre.  $mysql[$dong].";";
			$result =& $ctkthtDao->retrieve($mysqlQ);
			if (!$result)
			{
				echo "1";
				return;
			}
		}

	}

	function Edit_CTKT($args, &$request) {
		$xMode  = Request::getUserVar("Mode");
		$journalid = Request::getUserVar('journalid') ;
		$Year = Request::getUserVar('year') ;
		$soct = Request::getUserVar("soct");
		$ngct = Request::getUserVar("ngct");
		$lydo = Request::getUserVar("lydo");
		$tableArr = Request::getUserVar("tableArr");
		$cautruc = Request::getUserVar("cautruc");
		$idphieu = Request::getUserVar('idphieu') ;


		$codulieu = 0;
		$succ = 1;
		$mysql = array();
		$i = 0;

		foreach ($tableArr as $v) {
			$dulieu = ""; 
			$mysql[$i] = "" ;

			foreach ($v as $key=>$value) 
			{
				$dulieu .= "$value";
				$fdulieu = "$value";
				if ($fdulieu !== "")
				{		$mysql[$i] .= ", ". $cautruc[$key]."  = '".$value."'";
				}
			}
			if ($dulieu !== "")
			{
				$i++;
			}

		}

		if ($i==0)
		{
			echo "2";
			return ;
		}

		//dang lam do dang
		$mysql_pa = "UPDATE CTKTTH".$journalid. $Year. "  SET ";
		$mysql_pa .= "  soct='". $soct. "', ";
		$mysql_pa .= "  ngct='". $ngct. "', ";
		$mysql_pa .= "  lydo='". $lydo. "' ";
		$mysql_pa .= "  where idPhieu = '".$idphieu."'";


		//echo $mysql_pa;
		$ctkthtDao =& DAORegistry::getDAO('CTKTTHDAO');
		$result =& $ctkthtDao->retrieve($mysql_pa);

		$mysqlQ = "DELETE FROM CTKTTHDT".$journalid. $Year. "  WHERE idPhieu='". $idphieu. "'";
		$result =& $ctkthtDao->retrieve($mysqlQ);


		$mysql_pre = "INSERT INTO CTKTTHDT".$journalid. $Year. "  SET idPhieu='". $idphieu . "'";
		for ($dong = 0; $dong < $i ; $dong++) {
			$mysqlQ = $mysql_pre.  $mysql[$dong].";";
			//echo $mysqlQ;
			$result =& $ctkthtDao->retrieve($mysqlQ);
			if (!$result)
			{
				echo "1";
				return;
			}
		}

	}

	function CTKTTH_In($args, &$request) {
		import('classes.acct.doiso');
		$idphieu  = Request::getUserVar("idphieu");
		$nam  = Request::getUserVar("nam");
		$noco  = Request::getUserVar("noco");
		$journal =& Request::getJournal();
		$journalid =$journal->getId();

		$query = "SELECT a.soct, a.ngct, a.hoten, a.diachi, a.lydo, a.TK , b.tkdu , b.sotienvn FROM CTKT" .$journalid. $nam . " a LEFT JOIN ctktdt".$journalid.$nam . " b ON (a.idphieu = b.idphieu) ";
		
		$query = $query . "WHERE a.idphieu = '". $idphieu ."' " ;
		$ctktDao =& DAORegistry::getDAO('CTKTDAO');
        $ctkts =& $ctktDao->getCTKT_ThuChi($query, $noco);
		$sotien = floatval($ctkts[0]["sotienvn"]);
		$bangchu = doiso($sotien);

		$templateMgr =& TemplateManager::getManager();
		$templateMgr->assign('soct', $ctkts[0]["soct"]);
		$templateMgr->assign('ngct', $ctkts[0]["ngct"]);
		$templateMgr->assign('hoten', $ctkts[0]["hoten"]);
		$templateMgr->assign('diachi', $ctkts[0]["diachi"]);
		$templateMgr->assign('lydo', $ctkts[0]["lydo"]);
		$templateMgr->assign('solgctg', $ctkts[0]["solgctg"]);
		if ($noco == "N")
		{
			$templateMgr->assign('tenphieu', "Phiếu Thu");
			$templateMgr->assign('tkno', $ctkts[0]['tk']);
			$templateMgr->assign('tkco', $ctkts[0]['tkdu']);
		}
		else
		{
			$templateMgr->assign('tenphieu', "Phiếu Chi");
			$templateMgr->assign('tkco', $ctkts[0]['tk']);
			$templateMgr->assign('tkno', $ctkts[0]['tkdu']);

		}



		//$templateMgr->assign_by_ref('ctkts', $ctkts);
		$templateMgr->assign('noco', $noco);
		$templateMgr->assign('sotien', $sotien);
		$templateMgr->assign('bangchu', $bangchu);
		$templateMgr->display('acctCN/ThuChi.tpl');
	}

	function listCTKTTH($baseurl) {

	
		$templateMgr =& TemplateManager::getManager();
		$user =& Request::getUser();
		$userId = $user->getId();
		$xma_dvcs = $user->getPath();
		$journal =& Request::getJournal();
		$journalid =$journal->getId();
		
		$gcNam  = Request::getUserVar("dateExpire1Year");
		$xThang1  = Request::getUserVar("dateExpire1Month");
	
		if ($xThang1)
		{
			$gcNam  = Request::getUserVar("dateExpire1Year");
			$gcNam2  = Request::getUserVar("dateExpire1Year");
			if ($gcNam !=$gcNam2)
			{
				echo '<script type="text/javascript">alert("Chi bao cao trong khoang thoi gian 1 nam"); </script>';
				return;
			}

			$xNgay1  = Request::getUserVar("dateExpire1Day");
			$xThang1  = Request::getUserVar("dateExpire1Month");
			$xNgay2  = Request::getUserVar("dateExpire2Day");
			$xThang2  = Request::getUserVar("dateExpire2Month");
			$date1 = mktime(0, 0, 0, $xThang1, $xNgay1, $gcNam);
			$date2 = mktime(0, 0, 0, $xThang2, $xNgay2, $gcNam);
			$ngay1 = date ( 'Y-m-d', $date1 );
			$ngay2 = date ( 'Y-m-d', $date2 );
		}
		else
		{
			$ngay1  = Request::getUserVar("ngay1");
			$ngay2  = Request::getUserVar("ngay2");
			if ($ngay1)
			{
				$gcNam = substr($ngay1,0,4);
			} 
			else
			{
				$xThang  =date("m", time());//
				$xNgay2  =date("d", time());//
				$xNgay1 = $xNgay2  - 10;
				if ($xNgay1 <=0)
					$xNgay1 = 1;
				$date1 = mktime(0, 0, 0, $xThang, $xNgay1, $gcNam);
				$date2 = mktime(0, 0, 0, $xThang, $xNgay2, $gcNam);
				$ngay1 = date ( 'Y-m-d', $date1 );
				$ngay2 = date ( 'Y-m-d', $date2 );
			}
		}

		$templateMgr->assign('xNam', $gcNam);

		$templateMgr->assign('Date1', $ngay1);  
		$templateMgr->assign('Date2', $ngay2);

		
		$ctktDao =& DAORegistry::getDAO('CTKTTHDAO');
		$dict = NewDataDictionary($ctktDao->_dataSource);
		$tables = $dict->MetaTables('TABLES', false);
		$tablename = "ctktth".$journalid. $gcNam;

		if (!in_array($tablename,$tables)) 
		{
			$ctktDao ->CreateTable($gcNam, $journalid );
		}


		$templateMgr->assign('loaiphieu', "B&#225;o n&#7907;/R&#250;t ti&#7873;n Ng&#226;n h&#224;ng");
		$templateMgr->assign('mact', "4-CTG");
		$templateMgr->assign('noco', "C");
		$templateMgr->assign('lTKDU', "TK N&#7907;");
		$templateMgr->assign('lTK', "TK C&#243;");
		if ($xmant == "VND")
			$templateMgr->assign('loaitk', "1121");
		else
			$templateMgr->assign('loaitk', "1122");


	
		$templateMgr->assign('action', "Chung tu ".$gcNam);


       // lay so lieu
		// them phan Search

		$searchType = null;
		$searchMatch = null;
		$search = Request::getUserVar('search');
		$searchInitial = Request::getUserVar('searchInitial');
		if (!empty($search)) {
			$searchType = Request::getUserVar('searchField');
			$searchMatch = Request::getUserVar('searchMatch');

		} elseif (!empty($searchInitial)) {
			$searchInitial = String::strtoupper($searchInitial);
			$searchType = USER_FIELD_INITIAL;
			$search = $searchInitial;
		}

		$fieldOptions = Array(
		CTKT_FIELD_TKDU => 'TK &#272;&#244;&#237; &#7913;ng ',
		CTKT_FIELD_SOCT => 'S&#7889; ch&#7913;ng t&#7915; ',
		CTKT_FIELD_DIENGIAI => 'Di&#7877;n gi&#7843;i ',
		CTKT_FIELD_SOTIENVN => 'S&#7889; ti&#7873;n '
			);
		$templateMgr->assign('fieldOptions', $fieldOptions);
		$templateMgr->assign('searchField', $searchType);
		$templateMgr->assign('searchMatch', $searchMatch);
		$templateMgr->assign('search', $search);
		$templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));



		///
		$searchTypeMap = array(
		CTKT_FIELD_TKDU => 'TKDU',
		CTKT_FIELD_SOCT => 'A.SOCT',
		CTKT_FIELD_DIENGIAI => 'DIENGIAI',
		CTKT_FIELD_SOTIENVN => 'B.SOTIENVN'
		);
		$paramArray = array();
		$searchSql = '';

		if (!empty($search) && isset($searchTypeMap[$searchType])) {
			$fieldName = $searchTypeMap[$searchType];
			switch ($searchMatch) {
				case 'is':
					$searchSql = "AND LOWER($fieldName) = LOWER(?)";
					$paramArray[] = $search;
					break;
				case 'contains':
					$searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
					$paramArray[] = '%' . $search . '%';
					break;
				case 'startsWith':
					$searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
					$paramArray[] = $search . '%';
					break;
			}
		}

		$xmant ="VND";
		$query = "SELECT a.idphieu, a.soct, a.ngct, b.diengiai, b.TKno , b.macttkno , b.tkco , b.macttkco, b.sotienvn  FROM CTKTTH".$journalid. $gcNam . " a LEFT JOIN ctktthdt".$journalid. $gcNam . " b ON (a.idphieu = b.idphieu) ";
		
		$query = $query . "WHERE DATE( a.ngct ) >= '" . $ngay1 . "' && DATE( a.ngct ) <=  '" . $ngay2 .  "'" ; 
		$query = $query . $searchSql;
		$query = $query . " ORDER BY ngct, soct";
		$rangeInfo = Handler::getRangeInfo('ctkts');
		$ctkts =& $ctktDao->getCTKTTH_view($query, $paramArray, $rangeInfo );
		

		$templateMgr->assign('journalid', $journalid);

		////
		$templateMgr->assign_by_ref('ctkts', $ctkts);

		//$newurlUpd = PKPRequest::getProtocol()."://". PKPRequest::getServerHost().PKPRequest::getBasePath()."/pages/acctCN/u_CTKTTH.php";

		$newurlRet = Request::url(null, 'index', 'CN_CTKT', null);
		
		$newurlDel = Request::url(null, 'acctCN', 'CTKTTH_Del', null);

		$newurl = Request::url(null, 'acctCN', 'CN_CTKT', null, array('Mode' => 'Edit', 'Nam' => $gcNam, "ngay1"=> $ngay1, 'ngay2'=>$ngay2));

		$templateMgr->assign('url', $newurl );
		$templateMgr->assign('urlRet', $newurlRet );

		//$newurlRFR = Request::url(null, null, 'CTKTTH', null, array('mant' => $xmant, 'Nam' => $gcNam, "ngay1"=> $ngay1, 'ngay2'=>$ngay2 ));
		$newurlRFR = Request::url(null, null, 'CN_CTKT', null, array('Nam' => $xNam, "ngay1"=> $ngay1, 'ngay2'=>$ngay2 ));

		$templateMgr->assign('urlRFR', $newurlRFR );

		//$templateMgr->assign('urlUpd', $newurlUpd);
		$templateMgr->assign('urlDel', $newurlDel);

		$CN_SecDetail2 ="Xem các chứng từ";
		$templateMgr->assign('CN_SecDetail2', $CN_SecDetail2);
		$templateMgr->assign('CN_SecDetail', "CN_KTTH");
		//$templateMgr->assign('searchSql', $searchSql);

		$templateMgr->addStyleSheet($baseurl.'/styles/dm.css');
		$templateMgr->addJavaScript("classes/acct/js/ShowHintMATK.js");
		$templateMgr->display('acctCN/CTKTTHList.tpl');
	}


	function createDMTK() {
		$this->editDMTK();
	}

	function RFR_DMDV(){
		
		$journal =& Request::getJournal();
		$journalid =$journal->getId();;

		$dmdvdao =& DAORegistry::getDAO('DMDVDAO');
		$dmdv_initial = Request::getUserVar("dmdv_initial");;
		$dmdvString = $dmdvdao->getSetting($journalid, $dmdv_initial);
		echo $dmdvString ;
	}



	function getTen_DMDV(){
		
		//$journalid ='3'   ; ///& $router->getContext($request);
				$journal =& Request::getJournal();
		$journalid =$journal->getId();;

		$dmdvdao =& DAORegistry::getDAO('DMDVDAO');

		$dmdv_ma = Request::getUserVar("dmdv_madv");
		if (strlen($dmdv_ma)==0)
		{
			echo "";
			return;

		}
		$dmdv_initial = substr($dmdv_ma,0,1);

		$dmdv_ma .= '</a></b>-';
		$dmdvString = $dmdvdao->getSetting($journalid, $dmdv_initial);
		echo between ($dmdv_ma, '<br><b>', $dmdvString );

	}

	function getTen_DMTK(){
		$journal =& Request::getJournal();
		$journalid =$journal->getId();;
		$dmtkdao =& DAORegistry::getDAO('DMTKDAO');

		$dmtk_ma = Request::getUserVar("dmtk_matk");
		if (strlen($dmtk_ma)==0)
		{
			echo "";
			return;

		}
		$dmtk_ma .= '</a></b>-';
		$dmtkString = $dmtkdao->getSetting($journalid, 'tracuu');
		echo between ($dmtk_ma, '<br><b>', $dmtkString );

	}

	


	function edit_createCTKTTH($baseurl, $args)
	{   
		
		$this->validate();
		$this->setupTemplate(true);
		$journal =& Request::getJournal();
		$journalid =$journal->getId();

		import('classes.acct.form.CTKTTHForm');

		$CTKTTHForm = new CTKTTHForm(!isset($args) || empty($args) ? null : ( $args[0]));

		if ($CTKTTHForm->isLocaleResubmit()) {
			$CTKTTHForm->readInputData();
		} else {
			$CTKTTHForm->initData();
		}
		$templateMgr =& TemplateManager::getManager();
		//$templateMgr->addStyleSheet($baseurl.'/styles/CTKTTH.css');
		$templateMgr->addJavaScript("lib/pkp/js/lib/jquery/jquery.min.js");
		$templateMgr->addJavaScript("lib/pkp/js/lib/jquery/jquery.maskedinput.js");
		$templateMgr->addJavaScript("lib/pkp/js/lib/jquery/jquery.numberformatter-1.2.1.js");

		
		//$templateMgr->addJavaScript('classes/acct/js/ListCT.js');

		$templateMgr->assign('CTKTTHId', $this->CTKTTHId);


		$dmtkDao =& DAORegistry::getDAO('DMTKDAO');

		$dmtkString = $dmtkDao->getSetting($journalid, 'tracuu');
		$matkString = $dmtkDao->getSetting($journalid, 'matk');
		$matkAr = explode("-", $matkString);
		array_unshift($matkAr, "");

		$matkDVString = $dmtkDao->getSetting($journalid, 'tkdv');
		$matkCPString = $dmtkDao->getSetting($journalid, 'tkcp');

		$templateMgr->assign('dmtks', $dmtkString);
		$templateMgr->assign('matks', $matkString);
		$templateMgr->assign('matka', $matkAr);
		$templateMgr->assign('tkdvs', $matkDVString);
		$templateMgr->assign('tkcps', $matkCPString);

		
		$dmdvdao =& DAORegistry::getDAO('DMDVDAO');
		$dmdv_initial = "0";
		$dmdvString = $dmdvdao->getSetting($journalid, $dmdv_initial);

		$madvString = $dmdvdao->getSettingMADV($journalid, 'madv');
		$madvAr = explode("-", $madvString);
		array_unshift($madvAr, "");
		$templateMgr->assign('dmdv_initial',  $dmdv_initial);


		$templateMgr->assign('alphaList', explode(' ', __('common.InitList')));
		$templateMgr->assign('dmdvs',  $dmdvString);
		$templateMgr->assign('madvs',  $madvString);
		$templateMgr->assign('madva',  $madvAr);
		$templateMgr->assign('macps',  "");


		$xThang  = Request::getUserVar("dateExpire1Month");
		$xNam  = Request::getUserVar("dateExpire1Year");
		if (!$xNam)
			$xNam = Request::getUserVar("Nam");

		$sttChiTiet =1;
		$xmant  = "VND";
		$templateMgr->assign('loaitien', $xmant);
		$dmtkDao =& DAORegistry::getDAO('DMTKDAO');

		$templateMgr->assign('loaiphieu', "Chứng từ kế toán");
		$templateMgr->assign('noco', "N");
		$templateMgr->assign('lTK', "TK N&#7907;");
		$templateMgr->assign('lTKDU', "TK C&#243;");

		$dstk =& $dmtkDao->getDSMATK("");
		$templateMgr->assign('loaitk', "1111");

		$templateMgr->assign('tktien', $dstk);
		$templateMgr->assign('mact', $xChiTiet);
		
		$newurl = Request::url(null, null, 'CTKTTH', null, array('Mode' => 'Add', 'mant' => $xmant, 'ChiTiet' => $xChiTiet, 'Nam' => $xNam ));
		$templateMgr->assign('url', $newurl );

		$templateMgr->addJavaScript('lib/pkp/js/lib/jquery/plugins/validate/jquery.validate.min.js');
		$templateMgr->addJavaScript('lib/pkp/js/jqueryValidatorI18n.js');

		$host =  $dmtkDao->_dataSource->host;
		$username =  $dmtkDao->_dataSource->user;
		$password  = $dmtkDao->_dataSource->password;
		$databaseName = $dmtkDao->_dataSource->databaseName;

		

		$templateMgr->assign('host', $host);
		$templateMgr->assign('username', $username);
		$templateMgr->assign('password', $password);
		$templateMgr->assign('databaseName', $databaseName);
		$templateMgr->assign('journalid', $journalid);

		$templateMgr->assign('xNam', $xNam);
		$templateMgr->assign('xNamT', $xNam-1);


		/// 
		$xidPhieu  = Request::getUserVar("idPhieu");
		if ($xidPhieu == null)
		{
			$templateMgr->assign('action', "Th&#234;m ch&#7913;ng t&#7915; m&#7899;i");
		}
		else
		{
			$templateMgr->assign('action', "S&#7917;a ch&#7913;ng t&#7915;");
		}

		$ctktDao =& DAORegistry::getDAO('CTKTTHDAO');
		$dict = NewDataDictionary($ctktDao->_dataSource);
		$tables = $dict->MetaTables('TABLES', false);
		$tablename = "ctktth".$journalid. $xNam;
		if (!in_array($tablename,$tables)) 
		{
			$ctktDao ->CreateTable($xNam, $journalid );
		}


		$xidPhieu  = Request::getUserVar("idPhieu");
		if ($xidPhieu  !== null)
		{
			$query = "SELECT a.idphieu, a.soct, a.ngct, a.lydo, b.diengiai, b.tkno , b.macttkno, b.tkco , b.macttkco,  b.sotienvn  FROM CTKTTH".$journalid.$xNam . " a LEFT JOIN ctktthdt".$journalid . $xNam . " b ON (a.idphieu = b.idphieu)  where a.idphieu = '". $xidPhieu. "' ";

			$ctkts =& $ctktDao->getCTKTTH_edit($query);
			
			
			$i=0;
			$aCtkt_tkno = array();
			$aCtkt_tkco = array();
			$aCtkt_macttkno = array();
			$aCtkt_macttkco = array();
			$aCtkt_sotienvn = array();
			$aCtkt_diengiai = array();

			$ngay1  = Request::getUserVar("ngay1");
			$ngay2  = Request::getUserVar("ngay2");

			foreach ($ctkts as $key=>$row)
			{
				if ($i==0)
				{
					$soct = $row["soct"];
					$ngct = $row["ngct"];
					$lydo = $row["lydo"];
					$templateMgr->assign('soct', $soct);
					$templateMgr->assign('ngct', $ngct);
					$templateMgr->assign('lydo', $lydo);
				}
				$i++;
				$aCtkt_tkno[] = $row["tkno"];
				$aCtkt_tkco[] = $row["tkco"];
				$aCtkt_macttkno[] = $row["macttkno"];
				$aCtkt_macttkco[] = $row["macttkco"];
				$aCtkt_sotienvn[] = $row["sotienvn"];
				$aCtkt_diengiai[] = $row["diengiai"];

			}
			$templateMgr->assign('sodong', $i);
			$sa = implode(",,,", $aCtkt_tkno);
			$templateMgr->assign('tknoss', $sa);
			$sa = implode(",,,", $aCtkt_tkco);
			$templateMgr->assign('tkcoss', $sa);
			$sa = implode(",,,", $aCtkt_macttkno);
			$templateMgr->assign('macttknoss', $sa);
			$sa = implode(",,,", $aCtkt_macttkco);
			$templateMgr->assign('macttkcoss', $sa);
			$sa = implode(",,,", $aCtkt_sotienvn);
			$templateMgr->assign('sotienvnss', $sa);
			$sa = implode(",,,", $aCtkt_sotiennt);
			$sa = implode(",,,", $aCtkt_diengiai);
			$templateMgr->assign('diengiaiss', $sa);
			$templateMgr->assign('Mode', 'edit');
			$templateMgr->assign('idphieu', $xidPhieu);
			
			$CN_SecDetail2 ="Sửa chứng từ";
			//$newurlIns = PKPRequest::getProtocol()."://". PKPRequest::getServerHost().PKPRequest::getBasePath()."/pages/acctCN/u_CTKTTH.php";
			$newurlIns  = Request::url(null, null, 'Edit_CTKT', null, array('Nam' => $xNam, 'Mode'=> 'edit' ));

			$urlMain = Request::url(null, null, 'CN_CTKT', null, array('Nam' => $xNam, "ngay1"=> $ngay1, 'ngay2'=>$ngay2 ));
		}
		else
		{
			$newurlIns  = Request::url(null, null, 'Ins_CTKT', null, array('Nam' => $xNam, 'Mode'=> 'add' ));

			$urlMain = Request::url(null, null, 'CN_CTKT', null, array('Nam' => $xNam, 'Mode'=> 'add' ));

			$templateMgr->assign('sodong', 2);
			$CN_SecDetail2 ="Thêm mới chứng từ";
			$templateMgr->assign('Mode', 'add');
		}
		$urlS_DMDV = Request::url(null, 'acctCN', 'RFR_DMDV');
		$urlS_getTenDMDV = Request::url(null, 'acctCN', 'getTen_DMDV');
		$urlS_getTenDMTK = Request::url(null, 'acctCN', 'getTen_DMTK');

		//echo $newurlRFR ;
		$newurlIn = Request::url(null, 'acctCN', 'CTKTTH_In', null);
		$templateMgr->assign('urlIn', $newurlIn );


		$templateMgr->assign('idphieu', $xidPhieu);
		$templateMgr->assign('urlIns', $newurlIns);
		$templateMgr->assign('urlS_DMDV', $urlS_DMDV);
		$templateMgr->assign('urlS_getTenDMDV', $urlS_getTenDMDV);
		$templateMgr->assign('urlS_getTenDMTK', $urlS_getTenDMTK);
		$templateMgr->assign('urlMain', $urlMain);
		//echo $urlMain;

		$templateMgr->assign('CN_SecDetail', "CN_KTTH");
		$templateMgr->assign('CN_SecDetail2', $CN_SecDetail2);
		$CTKTTHForm->display();
	}
}

?>
